import { Component, OnInit } from '@angular/core';
import { ConsultantVO } from '../vo/ConsultantVO';
import { ApiService } from '../api/api.service';
import { ApiUrl } from '../api/ApiUrl';
import { ActivatedRoute } from '@angular/router';
import { Router } from '@angular/router';
@Component({
  selector: 'app-guwenmore',
  templateUrl: './guwenmore.page.html',
  styleUrls: ['./guwenmore.page.scss'],
})
export class GuwenmorePage implements OnInit {
  items: ConsultantVO[] = [];
  ibank: any;
  cbankname = '';
  constructor(private router: Router, public activatedRoute: ActivatedRoute, public api: ApiService) { }

  ngOnInit() {
    this.ibank = this.activatedRoute.snapshot.paramMap.get('iid');
    this.cbankname = this.activatedRoute.snapshot.paramMap.get('cname');
    console.log('cbankname:' + this.cbankname);
    this.onSearch('0', null);
  }
  onSearch(iid: string = '0', evt: any) {
    this.api.getItems<ConsultantVO>(ApiUrl.getConsultantListByIbank, { 'iid': iid, 'ibank': this.ibank }).subscribe(response => {
      if (evt) {
        evt.target.complete();
      }
      if (response === null || response.length === 0) {
        console.log('没有数据返回');
        return;
      }
      this.items = this.items.concat(response);
      console.log(response);

    }, () => {
      if (evt) {
        evt.target.complete();
      }

      console.log('出错了');
    });
  }
  doUpRefresh(evt) {
    console.log('上拉刷新');
    this.onSearch(this.items[this.items.length - 1].iid, evt);
  }
  goToDetails(iid) {
    this.router.navigate(['/guwendetails', {'iid': iid}]);
  }
}
